<?php

include_once("services/FacebookProxy.php");
include_once("data/dao/FriendCodeDAO.php");
include_once("data/dao/CollectionDAO.php");
include_once("data/dao/WishListDAO.php");
include_once("data/dao/UsersDeletedDAO.php");
include_once("data/dao/UserDAO.php");

class UserRemover{
	
	private $user;
	private $facebook; 
	
	public function UserRemover(){

		$this->facebook = new FacebookProxy();
		$this->user = $this->facebook->getLoggedInUser();
		
		// this prevents a user opening delete.php
		// and being removed
		if($_REQUEST['confirm-delete'] == "true")
			$this->deleteUser($this->user);		
	}
	
	public function deleteUser($userId){
		
		//remove friend codes
		$fcdao = new FriendCodeDAO();
		$fcdao->deleteFriendCodeById($userId);
		
		//remove wish list
		$wldao = new WishListDAO();
		$wldao->deleteWishList($userId);
		
		//remove collection
		$cdao = new CollectionDAO();
		$cdao->deleteCollection($userId);
		
		//remove user
		$udao = new UserDAO();
		$udao->deleteUser($userId);
		
		//create a record of the deleted user
		$uddao = new UsersDeletedDAO();
		$uddao->addDeletedUser($userId);
		
		header("Location: " . $this->facebook->getFacebookUrl());
	}	
}
$ur = new UserRemover();
?>
